<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 引入样式 -->
  {$h->import('static/css/common.css')}
  {$h->import('static/css/public.css')}
    <link rel="stylesheet" href="/unpkg/lib-master/theme-chalk/index.css"> 
  <style>
    *{
      margin: 0px;
      padding: 0px;
    }
    .cell{
      text-align: center;
    }
    .secondBox{
      width: 80%;
      height: 600px;
      /* background: palegreen; */
    }
    .secondBox h3{
      height: 30px;
      background: rgb(245,245,245);
      line-height: 30px;
      font-size: 12px;
      font-weight: 600;
      padding-left: 10px;
    }
    .upload{
      width: 100%;
      height: 120px;
      /* background: red; */
    }
    .upload span{
      font-size: 12px;
    }
    .uploadDiv{
      margin: 20px 0px 0px 64px;
    }
    .inputLarge{
      width: 70%;
      height: 24px;
      padding-left: 6px;
      border: 1px solid rgb(211,212,214);
    }
    /*  */
    #uploadDemo{
      display: inline;
    }
    .upload-demo .el-upload-list{
      /* display: none; */
    }
    .uploadDiv p{
      font-size: 12px;
      margin: 20px 0px 0px 66px;
    }
    .uploadDiv p a{
      text-decoration: none;
      color: rgb(34,161,255);
      
    }
    .spInpu{
      margin-top: 20px;
      
    }
    .But{
      margin-top: 20px;
      margin-left: 66px;
    }
  
    /* 初始 button input */
   /*dao hang*/
    .public-header-nav{
      background: #fff;
      border-bottom: 1px solid #e6e6e6;
      display: flex;
      align-items: center;
      margin: 16px 16px 0 16px;
      border-radius: 4px 4px 0px 0px;
    }
    .public-header-nav li{
      list-style: none;
    }
    .public-header-nav li a{
      color: #333;
      font-size: 14px;
      line-height: 47px;
      padding: 0 20px;
      display: block;
      text-decoration: none;
    }
    .public-header-nav-active{
      color: #1E9FFF !important;
      border-bottom: 2px solid #1E9FFF !important;
    }
  </style>
</head>
<body>
<ul class="public-header-nav">
     <li><a href="index.html">活动列表</a></li>
     <li><a href="fission_statistics.html">数据分析</a></li>
     <li><a href="convert_list.html" class="public-header-nav-active" >群裂变兑换码</a></li>
      <!-- <li><a href="set_gzh.html">公众号配置</a></li> -->
</ul>
<div id="index" style="padding: 15px;">
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="奖品管理" name="first">
        <div class="cantainer">
          <el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%">
            <el-table-column
              label="编号"
              width="280">
              <template slot-scope="scope">
                <span style="margin-left: 10px">!{!{ scope.row.id }}</span>
              </template>
            </el-table-column>
            
            <el-table-column
            label="标题"
            width="280">
            
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                  !{!{scope.row.name }}
                </div>
            </template>
          </el-table-column>
          
            <el-table-column
              label="日期"
              width="280">
              <template slot-scope="scope">
                <i class="el-icon-time"></i>
                <span style="margin-left: 10px">!{!{timestampToTime(scope.row.ctime)}}  </span>
              </template>
            </el-table-column>
          
            <el-table-column label="操作">
              <template slot-scope="scope">
                <span class="table-public-btn" @click="handleEdit(scope.$index, scope.row)">管理</span>
                <span class="table-public-btn" @click="handleDelete(scope.$index, scope.row)">删除</span>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" layout="prev, pager, next" :total="tableData.length">
         </el-pagination>
        </div>
      </el-tab-pane>
    <el-tab-pane label="添加奖品" name="second">
      <div class="secondBox">
        <h3>兑换码设置</h3>
        <div class="upload">
          <div class="uploadDiv">
            <span>上传兑换码</span>  
            <el-upload id="uploadDemo" class="upload-demo"
              action="upload_file.html"
              limit="1"
              :file-list="fileList"
              :on-success='success'
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
            <p>请上传csv格式表格，一行一个码，<a href="download_csv.html">【点击下载格式】</a> <a href="http://tool.c7sky.com/password/" target="_Blank">【点击生成兑换码】</a></p>
            <div class="spInpu">
              <span>兑换码名称 <input type="text" id="code_name" class="inputLarge"></span>
              <input type="hidden" id="file_path" class="inputLarge"  v-model='valueNew'>
            </div>
            <el-button type="primary" class="But" @click='tijiao'>提交</el-button>
          </div>
         
        </div>
      </div>
    </el-tab-pane>
  </el-tabs>
</div>

</body>
</html>
 <!-- 引入Vue , ElementUi库 -->
<script src="/unpkg/unpkg.vue.js"></script>
<script src="/unpkg/lib-master/index.js"></script>
  {$h->import('static/layui/layui.js')}
  {$h->import('static/js/ajax.js')}
<script>
 
   const add = new Vue({
     
    el:"#index",
    data:{
      activeName:'first',
      currentPage:1, //初始页
      pagesize:10,    //    每页的数据
      // 表格数据
      tableData: {$etList},
      // 上传服务器数组
      fileList: {},
      valueNew:''
    },
    methods: {
      success(file){
        console.log(file.data.filePath);
        this.valueNew=file.data.filePath;
      },
       // 初始页currentPage、初始每页数据数pagesize和数据data
       handleSizeChange: function (size) {
          this.pagesize = size;
          console.log(this.pagesize)  //每页下拉显示数据
        },
        handleCurrentChange: function(currentPage){
                this.currentPage = currentPage;
                console.log(this.currentPage)  //点击第几页
        },
      // Tab 切换
      handleClick(tab, event) {
        console.log(tab, event);
      },
      // 编辑
      handleEdit(index, row) {
        window.location.href="convert_deltal.html?d_id="+row.id;
      },
      // 删除
      handleDelete(index, row) {
        myAjaxPost(false, true, 'stage_prize_delete.html', { id:row.id}, function (resp) {
            if (resp.status == 'success') {
            tusi(resp.msg);
            window.location.reload()
              
            }else{
              alert(resp.msg);
              
            }
        });
      },
      timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        // let Y = date.getFullYear() + '-';
        // let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        // let D = date.getDate() + ' ';
        // let h = date.getHours() + ':';
        // let m = date.getMinutes() + ':';
        // let s = date.getSeconds();
        // return Y+this.padLeftZero(M)+this.padLeftZero(D)+this.padLeftZero(h)+this.padLeftZero(m)+this.padLeftZero(s);
        let y = date.getFullYear();
        let MM = date.getMonth() + 1;
        MM = MM < 10 ? ('0' + MM) : MM;
        let d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        let h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        let m = date.getMinutes();
        m = m < 10 ? ('0' + m) : m;
        let s = date.getSeconds();
        s = s < 10 ? ('0' + s) : s;
        return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
      },
      tijiao(){
      var code_name=$('#code_name').val();
      var file_path=$('#file_path').val();
        myAjaxPost(false, true, 'add_convert_list.html', { name:code_name,file_path:file_path}, function (resp) {
        if (resp.status == 'success') {
        tusi(resp.msg);
        window.location.reload()
          
        }else{
          alert(resp.msg);
          if(resp.data == 1){
            $('#file_path').val('');
            $('#file_name').val('');
            $('#file_name_show').html('');
          }
        }
        });
      }
    },
    

  })
</script>